package com.example.bottmmenu.fragment;

import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.bumptech.glide.Glide;
import com.example.bottmmenu.MainActivity;
import com.example.bottmmenu.R;
import com.youth.banner.Banner;

import java.util.ArrayList;
import java.util.List;

public class HomeFragment extends Fragment {
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
//        return super.onCreateView(inflater, container, savedInstanceState);
        return inflater.inflate(R.layout.fragment_home, container, false);
    }

    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        final Activity MainActivity = getActivity();

//        Button button = (Button) MainActivity.findViewById(R.id.test);
//        button.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                Toast.makeText(MainActivity, "test" , Toast.LENGTH_SHORT).show();
//            }
//        });

        //设置图片资源:url或本地资源
        String[] images= new String[] {
                String.valueOf(Uri.parse("res:///" + R.drawable.law_0)),
                "https://p1.itc.cn/q_70/images03/20211209/475f0bc290774782aa24bb65bf3b49c2.png",
                "https://p1.itc.cn/q_70/images03/20211209/475f0bc290774782aa24bb65bf3b49c2.png",
                "https://p1.itc.cn/q_70/images03/20211209/475f0bc290774782aa24bb65bf3b49c2.png",
                "F:\\AndroidApk\\bottem-menu-master\\BottmMenu\\app\\src\\main\\res\\drawable\\law_0.jpg"
        };

        ArrayList<Integer> imagePath = new ArrayList<>();
        imagePath.add(R.drawable.law_0);
        imagePath.add(R.drawable.law_1);
        imagePath.add(R.drawable.law_0);
        imagePath.add(R.drawable.law_1);


        Banner banner = (Banner) MainActivity.findViewById(R.id.banner);
        banner.setBannerStyle(Banner.CIRCLE_INDICATOR_TITLE);
        banner.setIndicatorGravity(Banner.CENTER);
        banner.isAutoPlay(true);
        banner.setDelayTime(3000);
        banner.setImages(imagePath, new Banner.OnLoadImageListener() {
            @Override
            public void OnLoadImage(ImageView view, Object url) {
                System.out.println("加载中");
                Glide.with(MainActivity.getApplicationContext()).load(url).into(view);
                System.out.println("加载完");
            }
        });
        banner.setOnBannerClickListener(new Banner.OnBannerClickListener() {
            @Override
            public void OnBannerClick(View view, int position) {
                Toast.makeText(MainActivity.getApplicationContext(), "你点击了：" + position, Toast.LENGTH_LONG).show();
            }
        });


    }

}
